package persistence;

import java.util.List;

public class User {
	private int id;
	private String name;
	private String password;
	private Boolean isActive;
	private LibraryLocation location;
	private List<Role> roles;
	
	protected User(){}
	
	protected User(int id, String name, String password, Boolean isActive, LibraryLocation location, List<Role> roles) {
		setId(id);
		setName(name);
		setPassword(password);
		setActive(isActive);
		setLocation(location);
		setRoles(roles);
	}

	/*
	 * Important: only use fields for equals that will remain constant,
	 * because if one field used for comparison changes, return value of 
	 * equals changes too 
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		result = prime * result
				+ ((location == null) ? 0 : location.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (id != other.id)
			return false;
		if (location == null) {
			if (other.location != null)
				return false;
		} else if (!location.equals(other.location))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("User: id=").append(this.id).append(", name=").append(this.name).
		append(", password=").append(this.password).append(", isActive: ").append(this.isActive).
		append(", LibraryLocation=").append(this.location).append(", roles: ").append(this.roles);
		return builder.toString();
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	public Boolean isActive() {
		return isActive;
	}
	
	public void setActive(Boolean isActive) {
		this.isActive = isActive;
	}

	public LibraryLocation getLocation() {
		return location;
	}

	public void setLocation(LibraryLocation location) {
		this.location = location;
	}

	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
}